package com.bwstudio.demo.consumer;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import com.bwstudio.demo.consumer.util.ExceptionUtil;

@EnableFeignClients
@SpringBootApplication
@EnableDiscoveryClient
public class Application {



	// 实例化 RestTemplate 实例
//	@Bean
//	public RestTemplate restTemplate() {
//		return new RestTemplate();
//	}
	
	/*
	 * 实例化 带fallback的RestTemplate 实例 
	 * blockHandlerClass：限流后处理的类
	 * blockHandler：限流后处理的方法 
	 * fallbackClsss：熔断后处理的类 
	 * fallback：熔断后处理的方法
	 */
	
	@Bean
	@LoadBalanced
	@SentinelRestTemplate(
			blockHandler = "handleException", 
			blockHandlerClass = ExceptionUtil.class,
			fallback = "fallback", 
			fallbackClass = ExceptionUtil.class)
	public RestTemplate restTemplate() {
	    return new RestTemplate();
	}

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}
